using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Threading;
using SqlWebAdmin.CSharp;

public partial class TableProperties : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
           
                lblError.Text = string.Empty;
                lblError.Visible = false;

				Server smoServer = SmoHelper.GetServer();
                try
                {
                    

                    string databaseName = Request.QueryString["database"];
                    Database smoDatabase = smoServer.Databases[databaseName];

                    if (smoDatabase != null)
                    {
                        string tableName = Request.QueryString["table"];
                        string tableSchema = Request.QueryString["schema"];
                        Microsoft.SqlServer.Management.Smo.Table smoTable = smoDatabase.Tables[tableName, tableSchema];

                        if (smoTable != null)
                        {
                            lblNameProperty.Text = HttpUtility.HtmlEncode(smoTable.Name);
                            lCreateDate.Text = HttpUtility.HtmlEncode(smoTable.CreateDate.ToString(Thread.CurrentThread.CurrentUICulture));
                            lDataSpaceUsed.Text = (smoTable.DataSpaceUsed / 1024).ToString(Thread.CurrentThread.CurrentUICulture);
                            lDateLastModified.Text = HttpUtility.HtmlEncode(smoTable.DateLastModified.ToString(Thread.CurrentThread.CurrentUICulture));
                        
                        }
                        else
                        {
                            Response.Redirect(String.Format("error.aspx?error={0}", Globals.tableNotFoundErrorNumber), false);
                        }
                        

                    }
                    else
                    {
                        Response.Redirect(String.Format("error.aspx?error={0}", Globals.databaseNotFoundErrorNumber), false);
                    }
                }
                catch (SmoException smoEx)
                {
                    lblError.Text = HttpUtility.HtmlEncode(Common.ConcatenateExceptions(smoEx));
                    lblError.Visible = true;
                }
                catch (System.Exception ex)
                {
                    lblError.Text = HttpUtility.HtmlEncode(Common.ConcatenateExceptions(ex));
                    lblError.Visible = true;
                }

            
        }
    }
}
